package xaj.meta.util.mapping;

import java.util.ArrayList;
import java.util.List;

import polyglot.util.ErrorInfo;

import xaj.scc.ExtensionInfo;

public class errorMapping {

		
		protected List<erro> msg ;
		
		private static errorMapping instance = null;
		//Padrao singleton
		public static errorMapping getInstance() {
			if (instance == null) {
				instance = new errorMapping();
			}
			return instance;
		}
		private errorMapping(){
			msg = new ArrayList<erro>();
		}
		
		/**
		 * 
		 * @param emsg- termo ou simbolo nao encontrado nos mapeamentos
		 * @param place- local no projeto onde ocorrido o erro
		 */
		public void sentError(String emsg,String place){
			erro e = new erro(emsg,place);
			msg.add(e);
			//TODO
			
			String note = buildError(emsg,place);
			ExtensionInfo.getFilaErros().enqueue(ErrorInfo.SEMANTIC_ERROR, note);
		}
		
		public String toString(){
			String imp="No errors";
			
			for(int i = 0 ; i<msg.size();i++){
				if(i == 0) imp = "";
				imp += msg.get(i).toString()+"\n";
				
			}
			return imp;
		}
		
		
	protected String buildError(String id,String place){
		String message="";
		
		message = "Error ocurred when try to find "+id+" in mapping, at "+place;
		
		return message;
	}
	
	class erro{
		public String notif;
		public String place;
		
		private erro(){
			notif = place = "";  
		}
		private erro(String notif,String when){
			this.notif = notif;
			this.place = when;
		}
		public String toString(){
			String imp;
			imp = "Error  ocurreded: "+notif+ " in "  +place+ " no exists in grammar";
			return imp;
		}
	}

}
